package com.tmc.util;

import com.sun.xml.bind.v2.runtime.Location;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;
import com.tmc.vendor.inthotel.dida.bean.getBedType.BedType;
import com.tmc.vendor.inthotel.dida.bean.getBedType.BedTypeSuccess;
import com.tmc.vendor.inthotel.dida.bean.getBedType.GetBedTypeListRS;
import com.tmc.vendor.inthotel.dida.bean.getBreakfast.Breakfast;
import com.tmc.vendor.inthotel.dida.bean.getBreakfast.BreakfastSuccess;
import com.tmc.vendor.inthotel.dida.bean.getBreakfast.GetBreakfastTypeListRS;
import com.tmc.vendor.inthotel.dida.bean.getCity.City;
import com.tmc.vendor.inthotel.dida.bean.getCity.CitySuccess;
import com.tmc.vendor.inthotel.dida.bean.getCity.GetCityListRS;
import com.tmc.vendor.inthotel.dida.bean.getCountry.Country;
import com.tmc.vendor.inthotel.dida.bean.getCountry.CountrySuccess;
import com.tmc.vendor.inthotel.dida.bean.getCountry.GetCountryListRS;
import com.tmc.vendor.inthotel.dida.bean.getPropertyCategory.GetPropertyCategoryListRS;
import com.tmc.vendor.inthotel.dida.bean.getPropertyCategory.PropertyCategory;
import com.tmc.vendor.inthotel.dida.bean.getPropertyCategory.PropertyCategorySuccess;
import com.tourico.schemas.webservices.hotelv3.Hotel;
import com.tourico.schemas.webservices.hotelv3.RoomType;
import com.tourico.webservices.hotelv3.detail.Amenity;
import com.tourico.webservices.hotelv3.detail.Description;
import com.tourico.webservices.hotelv3.detail.Descriptions;
import com.tourico.webservices.hotelv3.detail.Facility;
import com.tourico.webservices.hotelv3.detail.FreeTextShortDescription;
import com.tourico.webservices.hotelv3.detail.Home;
import com.tourico.webservices.hotelv3.detail.HotelRoomTypeId;
import com.tourico.webservices.hotelv3.detail.Image;
import com.tourico.webservices.hotelv3.detail.LongDescription;
import com.tourico.webservices.hotelv3.detail.Media;
import com.tourico.webservices.hotelv3.detail.RefPoints;
import com.tourico.webservices.hotelv3.detail.ShortDescription;
import com.tourico.webservices.hotelv3.detail.StatusCode;
import com.tourico.webservices.hotelv3.detail.TWS_HotelDetailsV3;
import com.tourico.webservices.hotelv3.detail.VoucherRemark;

public class XStreamUtil {

	private static XStream respXStream = null;
	
	private static XStream reqXStream = null;
	
	public static XStream getRespXStream(){
		if (respXStream == null){
			respXStream = new XStream(new DomDriver());
			respXStream.autodetectAnnotations(true); 
			respXStream.alias("GetCountryListRS", GetCountryListRS.class);
			respXStream.alias("CountrySuccess",CountrySuccess.class);
			respXStream.alias("Country", Country.class);
			respXStream.alias("GetCityListRS", GetCityListRS.class);
			respXStream.alias("CitySuccess",CitySuccess.class);
			respXStream.alias("City", City.class);
			respXStream.alias("GetBedTypeListRS", GetBedTypeListRS.class);
			respXStream.alias("BedTypeSuccess",BedTypeSuccess.class);
			respXStream.alias("BedType", BedType.class);
			respXStream.alias("GetBreakfastTypeListRS", GetBreakfastTypeListRS.class);
			respXStream.alias("BreakfastSuccess",BreakfastSuccess.class);
			respXStream.alias("Breakfast", Breakfast.class);
			respXStream.alias("GetPropertyCategoryListRS", GetPropertyCategoryListRS.class);
			respXStream.alias("PropertyCategorySuccess",PropertyCategorySuccess.class);
			respXStream.alias("PropertyCategory", PropertyCategory.class);
			
			//解析detail下类
			respXStream.alias("Amenity",Amenity.class);
			respXStream.alias("Description", Description.class);
			respXStream.alias("Descriptions", Descriptions.class);
			respXStream.alias("Facility",Facility.class);
			respXStream.alias("FreeTextShortDescription",FreeTextShortDescription.class);
			respXStream.alias("Home",Home.class);
			respXStream.alias("Hotel",Hotel.class);
			respXStream.alias("HotelRoomTypeId",HotelRoomTypeId.class);
			respXStream.alias("Image",Image.class);
			respXStream.alias("Location",Location.class);
			respXStream.alias("LongDescription",LongDescription.class);
			respXStream.alias("Media",Media.class);
			respXStream.alias("RefPoints",RefPoints.class);
			respXStream.alias("RoomType",RoomType.class);
			respXStream.alias("ShortDescription",ShortDescription.class);
			respXStream.alias("StatusCode",StatusCode.class);
			respXStream.alias("TWS_HotelDetailsV3",TWS_HotelDetailsV3.class);
			respXStream.alias("VoucherRemark",VoucherRemark.class);
		} 
		return respXStream;
	}
	
	public static XStream getReqXStream(){
		if (reqXStream == null){
			reqXStream = new XStream(new DomDriver());
			respXStream.autodetectAnnotations(true); 
		}
		return reqXStream;
	}
	
	@SuppressWarnings("unchecked")
	public static <T> T fromXml(String xml){
		return (T) getRespXStream().fromXML(xml);
	}
	
	public static String toXml(Object obj){
		return getReqXStream().toXML(obj);
	}
}
